package com.kevin.listadapter;

import java.util.List;

import com.kevin.testadapter.R;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Adapter4List extends ArrayAdapter<ChattingItemImg> {
	private final static String TAG = "Adapter4List";
	private int mResourceId;

	public Adapter4List(Context context, int resourceId, List<ChattingItemImg> objects) {
		super(context, resourceId, objects);
		mResourceId = resourceId;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Log.d(TAG, "getView at position: " + position);

		LinearLayout itemView = null;

		ChattingItemImg item = getItem(position);
		if (null == convertView) {
			itemView = new LinearLayout(getContext());
			String service = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater li = (LayoutInflater) getContext().getSystemService(service);
			li.inflate(mResourceId, itemView, true);
		} else {
			itemView = (LinearLayout) convertView;
		}

		TextView tvImgId = (TextView) itemView.findViewById(R.id.tv_img_id);
		TextView tvImgPath = (TextView) itemView.findViewById(R.id.tv_img_path);

		tvImgId.setText(String.valueOf(item.mImgId));
		tvImgPath.setText(item.mFilePath);

		return itemView;
	}

}
